package com.ruoyi.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.user.domain.UserTotalCapital;
import com.ruoyi.user.service.IUserTotalCapitalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资金余额Controller
 * 
 * @author DEREK
 * @date 2023-05-22
 */
@RestController
@RequestMapping("/user/userCapital")
public class UserTotalCapitalController extends BaseController
{
    @Autowired
    private IUserTotalCapitalService userTotalCapitalService;

    /**
     * 查询资金余额列表
     */
    @PreAuthorize("@ss.hasPermi('user:userCapital:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserTotalCapital userTotalCapital)
    {
        startPage();
        List<UserTotalCapital> list = userTotalCapitalService.selectUserTotalCapitalList(userTotalCapital);
        return getDataTable(list);
    }

    /**
     * 导出资金余额列表
     */
    @PreAuthorize("@ss.hasPermi('user:userCapital:export')")
    @Log(title = "资金余额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserTotalCapital userTotalCapital)
    {
        List<UserTotalCapital> list = userTotalCapitalService.selectUserTotalCapitalList(userTotalCapital);
        ExcelUtil<UserTotalCapital> util = new ExcelUtil<UserTotalCapital>(UserTotalCapital.class);
        util.exportExcel(response, list, "资金余额数据");
    }

    /**
     * 获取资金余额详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:userCapital:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userTotalCapitalService.selectUserTotalCapitalById(id));
    }

    /**
     * 新增资金余额
     */
    @PreAuthorize("@ss.hasPermi('user:userCapital:add')")
    @Log(title = "资金余额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserTotalCapital userTotalCapital)
    {
        return toAjax(userTotalCapitalService.insertUserTotalCapital(userTotalCapital));
    }

    /**
     * 修改资金余额
     */
    @PreAuthorize("@ss.hasPermi('user:userCapital:edit')")
    @Log(title = "资金余额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserTotalCapital userTotalCapital)
    {
        return toAjax(userTotalCapitalService.updateUserTotalCapital(userTotalCapital));
    }

    /**
     * 删除资金余额
     */
    @PreAuthorize("@ss.hasPermi('user:userCapital:remove')")
    @Log(title = "资金余额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userTotalCapitalService.deleteUserTotalCapitalByIds(ids));
    }
}
